package vsm.vsm_server.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.*;
import vsm.vsm_server.pojo.Notice.Notice;

import java.math.BigInteger;
import java.util.List;

@Mapper
public interface NoticeMapper {

    @Select("select * from notice where userId = #{userId} order by time desc")
    List<Notice> getAllNotice(BigInteger userId);

    @Insert("INSERT INTO notice (userId, senderId, type, time, isCheck, content,videoId) " +
            "VALUES (#{userId}, #{senderId}, #{type}, #{time}, false, #{content},#{videoId}) " +
            "ON DUPLICATE KEY UPDATE " +
            "time = VALUES(time)")
    void saveNotice(Notice notice);

    @Insert("INSERT INTO notice (userId, senderId, type, time, isCheck, content,videoId) " +
            "VALUES (#{userId}, #{senderId}, #{type}, #{time}, false, #{content},#{videoId}) ")
    void saveCommentNotice(Notice notice);

    @Select("select exists(select * from notice where userId = #{userId} and isCheck = false)")
    Boolean getExistNew(BigInteger userId);

    @Update("update notice set isCheck = true  where userId = #{userId}")
    void checkNewNotice(BigInteger userId);
}
